﻿function Helper() {
    this.AysGet = function (domain, func, async) {
        waitingDialog({ title: "Loading...", message: "Please wait." });

        //var domain = "/page/Handler1.ashx";
        var Async = false;
            if (async == false) {
                Async = false;
            }
        var uri = domain;
        jQuery.ajax({
            type: "get",
            url: uri,
            async: Async,
            dataType: "json",
            success: function (data) {
                if (func) {
                    if (data && data.Error === '-0') {
                        window.location = '/Page/login.aspx';
                    }
                    func(data);
                }
                //if (_methodName != 'GetCurrentUserDetail') {
                closeWaitingDialog();
                //}
            },
            error: function () {
                closeWaitingDialog();
            }
        });
    };
    this.AysPose = function (_methodName, _postData, func, async) {
        waitingDialog({ title: "Loading...", message: "Please wait." });
        var domain = "/page/Handler1.ashx";
        var Async = false;
            if (async == false) {
                Async = false;
            }

        var _data = { metdhodName: _methodName, postData: _postData };
        var uriPost = domain;
        jQuery.ajax({
            type: "post",
            url: uriPost,
            async: Async,
            data: _data,
            dataType: "json",
            success: function (data) {
                if (func) {
                    if (data && data.Error === '-0') {
                        window.location = '/Page/login.aspx';
                    }
                    func(data);
                }
                //if (_methodName != 'GetCurrentUserDetail') {
                closeWaitingDialog();
                //}
            },
            error: function () {
                closeWaitingDialog();
            }
        });
    };

    this.getCourseData = function(func) {
        this.AysGet("/api/CourseAPI", func);
    };
    this.getMeasurementData = function(func) {
        this.AysGet("/api/Measurementapi", func);
    };
    this.getEmpTrainingData = function (func) {
        this.AysGet("/api/EmpTrainingAPI", func);
    };
    this.getCourseTimeUnitData = function (func) {
        this.AysGet("/api/CourseTimeUnitAPI", func);
    };
    this.getExpectKnowledgeTypeData = function (func) {
        this.AysGet("/api/ExpectKnowledgeTypeAPI", func);
    };
}
function waitingDialog (waiting) {
    jQuery("#loadingScreen").html(waiting.message + '' != waiting.message ? waiting.message : 'Please wait...');
    jQuery("#loadingScreen").dialog('option', 'title', waiting.title + '' != waiting.title ? waiting.title : 'Loading');
    jQuery("#loadingScreen").dialog('open');
    var top = (jQuery(window).height() - 80) / 2;
    var left = (jQuery(window).width() - 100) / 2;

    jQuery(".loadingScreenWindow").css('left', left);
    jQuery(".loadingScreenWindow").css('top', top);
};
function closeWaitingDialog() {
    jQuery("#loadingScreen").dialog('close');
};